/*						-*- coding: utf-8 -*- 
 * main.c	-- Polysh: le programme principal
 * 
 *           Author: Erick Gallesio [eg@unice.fr]
 *    Creation date: 22-May-2010 18:05 (eg)
 * Last file update: 25-May-2010 22:57 (eg)
 */

#include <stdio.h>
#include <stdlib.h>
#include "polysh.h"
#include "toplevel.h"
#include "environ.h"


int main(int argc, char *argv[])
{
  FILE *f = stdin;
  
  if (argc > 1) {
    /* On travaille sur un shell script */
    if ((f=fopen(argv[1], "r")) == NULL) {
      fprintf(stderr, "%s: cannot open `%s'\n", *argv, argv[1]);
      exit(1);
    }
    if (argc >= 2) 
      /* On passe les arguments au script */
      add_program_parameters_environ(--argc, ++argv);
  }
  else {
    /* Imprimer une bannière */
    fprintf(stderr, "Bienvenue sur %s version %s\n", SHELL_NAME, VERSION);
    add_program_parameters_environ(argc, argv);
  }

  
  toplevel(f);  /* Appeler le toplevel de l'interprete */
  
  if (argc == 1)
    /* on est interactif. Dire au revoir */
    fprintf(stderr, "Bye\n");

  return EXIT_SUCCESS;
}
